
/*param 1 return yyyy--MM-dd*/
export function get_now(num) {
  let date = new Date();
  var sign2 = ":";
  var year = date.getFullYear(); // 年
  var month = date.getMonth() + 1; // 月
  var day = date.getDate(); // 日
  var hour = date.getHours(); // 时
  var minutes = date.getMinutes(); // 分
  var seconds = date.getSeconds(); //秒
  var weekArr = [
    "星期日",
    "星期一",
    "星期二",
    "星期三",
    "星期四",
    "星期五",
    "星期六"
  ];
  var week = weekArr[date.getDay()];
  // 给一位数的数据前面加 “0”
  if (month >= 1 && month <= 9) {
    month = "0" + month;
  }
  if (day >= 0 && day <= 9) {
    day = "0" + day;
  }
  if (hour >= 0 && hour <= 9) {
    hour = "0" + hour;
  }
  if (minutes >= 0 && minutes <= 9) {
    minutes = "0" + minutes;
  }
  if (seconds >= 0 && seconds <= 9) {
    seconds = "0" + seconds;
  }
  // console.log([
  //   year + "-" + month + "-" + day,
  //   week,
  //   hour + sign2 + minutes + sign2 + seconds,
  // ])

  if (num == 1) {
    return year + "-" + month + "-" + day;
  } else if (num == 2) {
    return week;
  } else {
    return hour + sign2 + minutes + sign2 + seconds
  }

  // return [
  //   year + "-" + month + "-" + day,
  //   week,
  //   hour + sign2 + minutes + sign2 + seconds,
  // ];
}

export function get_yestoday() {
  const today = new Date();
  const yesterday = new Date(today);
  yesterday.setDate(yesterday.getDate() - 1); // 减去一天
  const year = yesterday.getFullYear();
  // 月份需要加1，因为getMonth返回的月份是0-11，而实际月份需要+1
  const month = yesterday.getMonth() + 1; 
  const day = yesterday.getDate();
 
  // 如果月份或日期小于10，则在前面添加一个'0'
  const pad = (num) => (num < 10 ? '0' + num : num);
 
  return `${year}-${pad(month)}-${pad(day)}`;
}

 
export function formatter_time(str) {
    if (str == undefined) { return '--' }
    str = str + "";
    var new_str = "";
    new_str =
        str.slice(0, 4) +
        "-" +
        str.slice(4, 6) +
        "-" +
        str.slice(6, 8) +
        " " +
        str.slice(8, 10) +
        ":" +
        str.slice(10, 12) +
        ":" +
        str.slice(12);
    return new_str;
}
 
export function formatter_time_fm_arr(arr) {
    if (arr == undefined) { return [] }
    let new_arr=arr.map((item,key)=>{
      return item= item.slice(8, 10) +":" + item.slice(10,12);
    });

    return new_arr;
   
}
 

export function diff_data(origin_data, ajax_data) {

  for (let item in ajax_data) {
    origin_data[item] = ajax_data[item]
  }

  return origin_data;

}

